package qeb.handheldmedical.patient;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import qeb.handheldmedical.R;
import qeb.handheldmedical.adapter.LisAdapter;
import qeb.handheldmedical.adapter.SlideListView;
import qeb.handheldmedical.helper.WSHelper;
import qeb.handheldmedical.model.InPatient;
import qeb.handheldmedical.model.InPatientLis;

public class LisQuery extends Activity {
	private SlideListView slideListView;
	private LisAdapter adapter;
	InPatient ip=new InPatient();
	InPatientLis ipl;
	private JSONArray JyJsonArray;
	private JSONObject jobj;
	private Button btn_title_back;
	private TextView tv_title; 
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		ip = (InPatient)getIntent().getSerializableExtra("patientinfo");
		setContentView(R.layout.query_lis);
		initView();
		 dataBind();		 
	}
	
	private void initView()
	{
		slideListView = (SlideListView) findViewById(R.id.slideListView5);
		tv_title=(TextView)findViewById(R.id.tv_top_title);
		tv_title.setText(ip.XM+"的检验列表");
		btn_title_back=(Button)findViewById(R.id.btn_title_back);
		btn_title_back.setOnClickListener(MyOnClickListener);
		//getData();

	}
	private void getData(){
			JyJsonArray = WSHelper.GetLisList(ip.ZYSJ,ip.CYSJ,ip.BAH,ip.HISZYXH);
	}
	/*系统主菜单点击事件（在院病人、门诊病人等）*/
	private OnClickListener MyOnClickListener=new OnClickListener(){		
		@Override
		public void onClick(View v) {
			// TODO 自动生成的方法存根LisAdapter
			//Bundle bundle=new Bundle();
			switch (v.getId()) {
			case R.id.btn_title_back://返回按钮
				LisQuery.this.finish();
				break;
			default:
				break;		
		}
		}
	};
	private void dataBind()
	{
		JyJsonArray = WSHelper.GetLisList(ip.ZYSJ,ip.CYSJ,ip.BAH,ip.HISZYXH);
		if (JyJsonArray != null && JyJsonArray.length() > 0) {
			adapter = new LisAdapter(JyJsonArray.length(),
					LisQuery.this, JyJsonArray);
			
			slideListView.setAdapter(adapter);
			
			slideListView.setOnItemClickListener(new OnItemClickListener() {

				public void onItemClick(AdapterView<?> parent, View view,
						int position, long id) {
					ipl = new InPatientLis();
					try {
						jobj = JyJsonArray.getJSONObject(position);
						ipl.getValue(jobj);
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						// e.printStackTrace();
					} catch (InstantiationException e) {
						// TODO Auto-generated catch block
						// e.printStackTrace();
					}
					if (ipl.ZXH != null && ipl.ZXH != "") {
						Intent intent = new Intent(getApplicationContext(),
								LisResultQuery.class);
						intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
						intent.putExtra("InPatientLisInfo", ipl);
						startActivity(intent);
					} else {
						Toast tt = Toast.makeText(LisQuery.this,
								"获取病人信息失败，请重试！", Toast.LENGTH_LONG);
						tt.show();
					}
				}

			});
		}
	}
}